<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>7.整数反转</title>
</head>

<body>

</body>

<script>
    /**
     * @param {number} x
     * @return {number}
     */
    var reverse = function (x) {
        let arr = x.toString().split('').reverse();
        if (arr.includes('-')) {
            arr.splice(arr.length - 1, 1);
            arr.unshift('-');
        }
        const min = Math.pow(-2, 31) - 1;
        const max = Math.pow(2, 31);
        let num = arr.join('') * 1;
        if (num > max || num < min) {
            return 0;
        } else {
            return num;
        }
    };
    console.log(reverse(123));

</script>

</html>